/*
 * TableResultView.java
 *
 * Created on 9. Juni 2008, 01:39
 */

package twi.result.table.view;

import javax.swing.JComponent;
import javax.swing.table.DefaultTableModel;

import twi.result.QueryResult;
import twi.result.table.RTable;
import twi.view.ResultView;

/**
 * 
 * @author Soeren
 */
public class TableResultView extends javax.swing.JPanel implements ResultView {

	/** Creates new form TableResultView */
	public TableResultView() {
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated
	// Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jScrollPane1 = new javax.swing.JScrollPane();
		jTable1 = new javax.swing.JTable();

		jScrollPane1.setName("jScrollPane1"); // NOI18N

		jTable1.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { { null, null, null, null },
						{ null, null, null, null }, { null, null, null, null },
						{ null, null, null, null } }, new String[] { "Title 1",
						"Title 2", "Title 3", "Title 4" }));
		jTable1.setName("jTable1"); // NOI18N
		jScrollPane1.setViewportView(jTable1);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400,
				Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300,
				Short.MAX_VALUE));
	}// </editor-fold>//GEN-END:initComponents

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTable jTable1;

	// End of variables declaration//GEN-END:variables
	@Override
	public JComponent getVisualComponent() {
		return this;
	}

	@Override
	public void setResult(QueryResult result) {
		RTable table = result.asTable();
		this.jTable1.setModel(new DefaultTableModel(table.getValues(true),
				table.getTitleRow()));
		validate();
	}

	public String getName() {
		return "Table";
	}

	@Override
	public void setup() {
		// TODO Auto-generated method stub

	}

}
